#include <stdio.h>
#include "crc8.h"

int main() {
    unsigned char data[9] = "123456789";

    CRC8_16 crc8_16;
    crc8_16.crcPoly = 0x9b;
    crc8_16.crcInit = 0x00;
    crc8_16.crcXor = 0x00;
    crc8_16.crcRefIn = 1;
    crc8_16.crcRefOut = 1;

    CRC8_256 crc8_256;
    crc8_256.crcPoly = 0x9b;
    crc8_256.crcInit = 0x00;
    crc8_256.crcXor = 0x00;
    crc8_256.crcRefIn = 1;
    crc8_256.crcRefOut = 1;

    unsigned char crc8;

    unsigned char i;

    create_crc8_table16(&crc8_16);
    crc8 = generate_crc8(&crc8_16, 16, data, 9);
    printf("0x%02x\n", crc8);

    printf("----------\n");

    create_crc8_table256(&crc8_256);
    crc8 = generate_crc8(&crc8_256, 256, data, 9);
    printf("0x%02x\n", crc8);

    printf("----------\n");

    prepare_crc8_with_table16(&crc8_16, &crc8);
    for(i = 0; i < 9; i++) {
        process_crc8_with_table16(&crc8_16, &data[i], &crc8);
    }
    complete_crc8_with_table16(&crc8_16, &crc8);
    printf("0x%02x\n", crc8);

    printf("----------\n");

    prepare_crc8_with_table256(&crc8_256, &crc8);
    for(i = 0; i < 9; i++) {
        process_crc8_with_table256(&crc8_256, &data[i], &crc8);
    }
    complete_crc8_with_table256(&crc8_256, &crc8);
    printf("0x%02x\n", crc8);

    return 0;
}
